import AMapLoader from '@amap/amap-jsapi-loader';
window._AMapSecurityConfig = {
  securityJsCode: '237716e4a44b4c1b1e45e9280e7f189f'
}
export const getLocationFn = (location) => {
  let address = [];
  AMapLoader.load({
    key: "3ec0f4b64da67a9e6ade01ba12078cf8", // 设置您的key
    version: "2.0",
    plugins: ["AMap.Geocoder"],
    AMapUI: {
      version: "1.1",
      plugins: []
    },
    Loca: {
      version: "2.0"
    }
  })
    .then((AMap) => {
      let geocoder;
      window.AMap.plugin('AMap.Geocoder', function () {
        geocoder = new window.AMap.Geocoder({
          // city 指定进行编码查询的城市，支持传入城市名、adcode 和 citycode
          // city: '全国'
        })
      })
      // 将地址转换成经纬度
      geocoder.getLocation(location, function (status, result) {
        if (status === 'complete' && result.geocodes.length) {
          console.log('根据经纬度获取到的地址', result.geocodes[0].location)
          address = [result.geocodes[0].location.lng, result.geocodes[0].location.lat];
          return address;
        } else {
          console.error('根据经纬度查询地址失败')
        }
      });
    })
    .catch((e) => {
      console.log(e);
    });
}